import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ylm_ui_kit/ylm_ui_kit.dart';

import '../ui/common_home_scaffold.dart';
import 'main_logic.dart';

class MainPage extends StatefulWidget {
  const MainPage({Key? key}) : super(key: key);

  @override
  State<MainPage> createState() => _MainPageState();
}

class _MainPageState extends CommonLifeState<MainPage> {
  late final MainLogic logic;
  final String page = Get.currentRoute;

  @override
  void initState() {
    super.initState();
    logic = Get.put(MainLogic());
  }

  @override
  void dispose() {
    Get.delete<MainLogic>();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return BaseScaffold(
      resizeToAvoidBottomInset: false,
      child: GetBuilder<MainLogic>(
        assignId: true,
        builder: (logic) {
          return logic.hasInitData
              ? CommonHomeScaffold(
                  logic.controller,
                  logic.pages,
                  logic.changePage,
                  const Color(0XFF05A5FC),
                  const Color(0XFF2D3230),
                )
              : const SizedBox.shrink();
        },
      ),
    );
  }

  @override
  String getRouteName() => page;

  @override
  void pageBack() => logic.pageBack();

  @override
  void pageClose() => logic.pageClose();

  @override
  void pageLeave() => logic.pageLeave();
}
